package 华为机试8月16日机试;

import java.util.Scanner;

public class 华为机试8月16日第1题2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String[] a = sc.nextLine().trim().split("\\s+");
            System.out.println(findMatch(a[0], a[1]));
        }
        sc.close();
    }

    private static int findMatch(String s, String s1) {
        if (s.length() != s1.length())
            return -1;
        int n = 0;
        int max = 0;
        boolean flag = false;
        for (int i = s.length() - 1; i >= 0; i--) {
            if (s.charAt(i) < '0' || s.charAt(i) > '9' || s1.charAt(i) < '0' || s1.charAt(i) > '9')
                return -1;
            if (s.charAt(i) == s1.charAt(i)) {
                if (flag)
                    n++;
                else {
                    n = 1;
                    flag = true;
                }
                max = max > n ? max : n;
            } else {
                flag = false;
                n = 0;
            }
        }
        if (max < 2)
            return 0;
        else
            return max;
    }
}
